home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 187_01 / dirfst.c < prev    next >
C/C++ Source or Header  |  1986-02-19  |  3KB  |  70 lines

  1. /*@*****************************************************/
  2. /*@                                                    */
  3. /*@ dirfst - search directory for first matching entry.*/
  4. /*@                                                    */
  5. /*@   Usage:     dirfst(path, dta, attr);              */
  6. /*@       where path is the full DOS path+filename.    */
  7. /*@            dta is the DOS func 0x4e work area      */
  8. /*@               (must be at least 44 bytes long).    */
  9. /*@            attr is the require file attributes:    */
  10. /*@                                                    */
  11. /*@               0x01 - read-only                     */
  12. /*@               0x02 - hidden                        */
  13. /*@               0x04 - system                        */
  14. /*@               0x08 - volume id                     */
  15. /*@               0x10 - directory                     */
  16. /*@               0x20 - archive bit(1=modified)       */
  17. /*@                                                    */
  18. /*@               0x08 excludes all others.  Others    */
  19. /*@               are additive.  0x00 implies read-only*/
  20. /*@               also.                                */
  21. /*@                                                    */
  22. /*@       returns a pointer to the file in the DTA.    */
  23. /*@          an extern of dirret contains the last     */
  24. /*@             DOS return code.                       */
  25. /*@                                                    */
  26. /*@          DTA looks like:                           */
  27. /*@                                                    */
  28. /*@               21 bytes - reserved for func 0x4f    */
  29. /*@                1 byte  - attributes found          */
  30. /*@                2 bytes - time of file              */
  31. /*@                2 bytes - date of file              */
  32. /*@                2 bytes - low word of file size     */
  33. /*@                2 bytes - high word of file size    */
  34. /*@ returns ===>  13 bytes - name and extension of file*/
  35. /*@                                                    */
  36. /*@                                                    */
  37. /*@*****************************************************/
  38.  
  39.  
  40. extern unsigned _rax, _rbx, _rcx, _rdx, _rsi, _rdi, _res, _rds;
  41. extern char _carryf, _zerof;
  42.  
  43. int dirret;
  44.  
  45. char *dirfst(path, dta, attr)
  46. char *path, *dta;
  47. int attr;
  48. {
  49.     int sav_carry, sav_rax;
  50.  
  51.     savedta();                /* save old dta */
  52.     setdta(dta);            /* use caller's area */
  53.     dirret = 0;                /* clear return code */
  54.  
  55.     _rds = _showds();        /* current data segment */
  56.     _rdx = path;            /* path offset */
  57.     _rcx = attr;            /* required attribute */
  58.     _rax = 0x4e00;            /* DOS find first function */
  59.     _doint(0x21);            /* call DOS */
  60.     sav_carry = _carryf;
  61.     sav_rax = _rax;
  62.     restdta();                /* reset to DOS's DTA */
  63.     if (!sav_carry)
  64.         return &dta[30];
  65.     else {
  66.         dirret = sav_rax;        /* save return code */
  67.         return 0;
  68.     }
  69. }
  70.